﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NaireSystem.Api.Dto;
using NaireSystem.Api.VO;
using NaireSystem.Datas;
using TYBase;

namespace NaireSystem.Api
{
    public class ExamApi
    {
        public static RPage<ExamVO> GetListMyCreateTest(PageInfo page, TestQueryDto queryDto)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getListMyCreateExam?{page.AsQueryData()}&{queryDto.AsQueryData()}")
                    .SetGet().Excute(out string data))
                {
                    return RPage<ExamVO>.Fail(data);
                }
                return data.AsModel<RPage<ExamVO>>();
            }
            catch (Exception ex)
            {
                return RPage<ExamVO>.Fail("获取数据失败!", ex);
            }
        }
        public static RPage<ExamVO> GetListMyCreateNaireTest(PageInfo page, TestQueryDto queryDto)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getListMyCreateNaireExam?{page.AsQueryData()}&{queryDto.AsQueryData()}")
                    .SetGet().Excute(out string data))
                {
                    return RPage<ExamVO>.Fail(data);
                }
                return data.AsModel<RPage<ExamVO>>();
            }
            catch (Exception ex)
            {
                return RPage<ExamVO>.Fail("获取数据失败!", ex);
            }
        }

        public static RPage<ExamVO> ListPublishExam(PageInfo page, TestQueryDto queryDto)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/listPublishExam?{page.AsQueryData()}&{queryDto.AsQueryData()}")
                    .SetGet().Excute(out string data))
                {
                    return RPage<ExamVO>.Fail(data);
                }
                return data.AsModel<RPage<ExamVO>>();
            }
            catch (Exception ex)
            {
                return RPage<ExamVO>.Fail("获取数据失败!", ex);
            }
        }
        //


        public static R<ExamWithDeptVo> GetExamWithDepts(string examUUid)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getExamWithDepts?examUUid={examUUid}")
                    .SetGet().Excute(out string data))
                {
                    return R<ExamWithDeptVo>.Fail(data);
                }
                return data.AsModel<R<ExamWithDeptVo>>();
            }
            catch (Exception ex)
            {
                return R<ExamWithDeptVo>.Fail("获取数据失败!", ex);
            }
        }

        public static R<Tbl_Exam> CreateTest(CreateTestDto createTest)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetData(createTest.JsonAsString())
                    .SetUrl($"/exam/create")
                    .SetPost().Excute(out string data))
                {
                    return R<Tbl_Exam>.Fail(data);
                }
                return data.AsModel<R<Tbl_Exam>>();
            }
            catch (Exception ex)
            {
                return R<Tbl_Exam>.Fail("创建失败!", ex);
            }
        }

        public static R<Tbl_Exam> GetItemById(string uuid)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getItemByUuid?uuid={uuid}")
                    .SetGet().Excute(out string data))
                {
                    return R<Tbl_Exam>.Fail(data);
                }
                return data.AsModel<R<Tbl_Exam>>();
            }
            catch (Exception ex)
            {
                return R<Tbl_Exam>.Fail("获取数据异常!", ex);
            }
        }

        internal static R<object> DeleteTest(string uuid)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/delete?uuid={uuid}")
                    .SetPost().Excute(out string data))
                {
                    return R<object>.Fail(data);
                }
                return data.AsModel<R<object>>();
            }
            catch (Exception ex)
            {
                return R<object>.Fail("删除数据异常!", ex);
            }
        }


        public static R<List<QtVO>> GetListQtByUuid(string uuid)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getListQtByUuid?uuid={uuid}")
                    .SetGet().Excute(out string data))
                {
                    return R<List<QtVO>>.Fail(data);
                }
                return data.AsModel<R<List<QtVO>>>();
            }
            catch (Exception ex)
            {
                return R<List<QtVO>>.Fail("获取问题列表数据异常!", ex);
            }
        }

        //

        internal static R<List<ExcellentInfo>> GetExcellentInfo(int examType)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getExcellentInfo?examType={examType}")
                    .SetGet().Excute(out string data))
                {
                    return R<List<ExcellentInfo>>.Fail(data);
                }
                return data.AsModel<R<List<ExcellentInfo>>>();
            }
            catch (Exception ex)
            {
                return R<List<ExcellentInfo>>.Fail("获取统计数据异常!", ex);
            }
        }

        internal static R<DissatisfiedInfo> GetDissatisfied(int examType)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getDissatisfied?examType={examType}")
                    .SetGet().Excute(out string data))
                {
                    return R<DissatisfiedInfo>.Fail(data);
                }
                return data.AsModel<R<DissatisfiedInfo>>();
            }
            catch (Exception ex)
            {
                return R<DissatisfiedInfo>.Fail("获取统计数据异常!", ex);
            }
        }

        internal static R<List<AveageScoreInfo>> GetAveageScoreByMonth(int examType)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/getAveageScoreByMonth?examType={examType}")
                    .SetGet().Excute(out string data))
                {
                    return R<List<AveageScoreInfo>>.Fail(data);
                }
                return data.AsModel<R<List<AveageScoreInfo>>>();
            }
            catch (Exception ex)
            {
                return R<List<AveageScoreInfo>>.Fail("获取按月统计数据异常!", ex);
            }
        }
        //

        internal static R<string> GetExamQrCode(string examUuid, int examType)
        {
            try
            {
                LocalHttp http = new LocalHttp();
                if (!http.SetBaseUri(AppData.Url)
                    .SetUrl($"/exam/createExamQRCoder?{new { examUuid = examUuid, examType = examType }.AsQueryData()}")
                    .SetGet().Excute(out string data))
                {
                    return R<string>.Fail(data);
                }
                return data.AsModel<R<string>>();
            }
            catch (Exception ex)
            {
                return R<string>.Fail("获取问题列表数据异常!", ex);
            }
        }
    }
}
